
//
//  MemberRechargeView.m
//  yameishe3
//
//  Created by pro on 2017/3/9.
//  Copyright © 2017年 yameishe. All rights reserved.
//

#import "MemberRechargeView.h"
@interface MemberRechargeView ()
{
    IBOutletCollection(UIButton)NSMutableArray * _moneyBtnArray;
    IBOutletCollection(UIButton)NSMutableArray * _payWayBtnArray;
    __weak IBOutlet UITextField *_moneyTF;
    __weak IBOutlet UIButton *_rachargeBtn;
    UIButton *_selectBtn;
    NSNumber* way;//记录当前选择支付方式 nil = 未选择  0 = 微信  1 = 支付宝  2 = 银联
}
@end
@implementation MemberRechargeView
-(void)awakeFromNib
{
    [super awakeFromNib];
    way = nil;
    [_moneyTF addTarget:self action:@selector(change) forControlEvents:UIControlEventEditingChanged];
}
-(void)change
{
    if ([NSNumber numberWithString:_moneyTF.text] != [NSNumber numberWithString:_selectBtn.titleLabel.text] && _selectBtn) {
        _selectBtn.selected = NO;
        _selectBtn = nil;
    }
}
-(IBAction)onTouchMoneyBtn:(UIButton*)sender
{
    for (UIButton *view in _moneyBtnArray) {
        view.selected = NO;
    }
    sender.selected = YES;
    _moneyTF.text = sender.titleLabel.text;
    if (sender == _selectBtn) {
        _selectBtn = nil;
        sender.selected = NO;
    }
    else
    {
        _selectBtn = sender;
    }
    [self checkBtnStatus];
}
-(IBAction)onTouchPayWayBtn:(UIButton*)sender
{
    for (UIButton *view in _payWayBtnArray) {
        view.selected = NO;
    }
    sender.selected = YES;
    way = [NSNumber numberWithInteger:sender.tag];
     [self checkBtnStatus];
}

-(void)checkBtnStatus
{
    if (!_moneyTF.text.length || !way ) {
        _rachargeBtn.enabled = NO;
    }
    else
    {
        _rachargeBtn.enabled = YES;
    }
}

-(IBAction)onTouchRecgharge:(id)sender
{

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
